package com.zhangmeng.online.exam.ui.components.callBack;

import com.zhangmeng.online.exam.ui.utils.ApiUtils;
import com.zhangmeng.online.exam.ui.api.DataLoad;
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
import com.zhangmeng.online.exam.ui.utils.FxUtils;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.stage.Stage;

/**
 * @author zm
 * @date 2025/3/14 15:35
 * @version: 1.0
 */
public class DynamicTableComponentCallBackImpl implements DynamicTableComponentCallBack {

    private DataLoad dataLoad;

    private Parent node;

    public DynamicTableComponentCallBackImpl(DataLoad dataLoad,Parent node) {
        this.dataLoad = dataLoad;
        this.node = node;
    }

    public DynamicTableComponentCallBackImpl(DataLoad dataLoad) {
        this.dataLoad = dataLoad;
    }
    @Override
    public ApiUtils.DataView flushData(Integer pageNum, Integer pageSize) {
//        System.out.println("刷新数据:" + pageNum + " " + pageSize);
        return dataLoad.loadData(pageNum, pageSize);
    }

    @Override
    public void Add(Parent node, Stage primaryStage, DynamicTableComponent table) {
//        Form form = (Form) node;
//        form.setTableComponent(table);
//        AlertUtils.alert("设置", node, primaryStage);
        FxUtils.alert("设置",node, primaryStage, false);
    }

    @Override
    public Parent getAddForm() {
        return this.node;
    }

    @Override
    public void delete(String s) {
        dataLoad.deleteData(s);
    }

    @Override
    public void edit(String id,DynamicTableComponent table) {
        Stage stage = (Stage) table.getScene().getWindow();
        dataLoad.editData(id, stage);
    }

    @Override
    public void update(DynamicTableComponent dynamicTableComponent, String id, String name, String oldValue, String newValue) {
        dataLoad.updateData(id, name, oldValue, newValue);
    }

    public DataLoad getDataLoad() {
        return dataLoad;
    }

    public void setDataLoad(DataLoad dataLoad) {
        this.dataLoad = dataLoad;
    }

    public Node getNode() {
        return node;
    }

    public void setNode(Parent node) {
        this.node = node;
    }
}
